import { create } from 'zustand';

/**
 * 应用状态
 */
interface AppState {
  // 侧边栏是否折叠
  collapsed: boolean;
  // 切换侧边栏折叠状态
  toggleCollapsed: () => void;
  // 设置侧边栏折叠状态
  setCollapsed: (collapsed: boolean) => void;

  // 面包屑
  breadcrumbs: { name: string; path?: string }[];
  // 设置面包屑
  setBreadcrumbs: (breadcrumbs: { name: string; path?: string }[]) => void;
}

/**
 * 应用 Store
 */
export const useAppStore = create<AppState>((set) => ({
  // 初始状态
  collapsed: false,
  breadcrumbs: [],

  // 切换侧边栏折叠状态
  toggleCollapsed: () => set((state) => ({ collapsed: !state.collapsed })),

  // 设置侧边栏折叠状态
  setCollapsed: (collapsed: boolean) => set({ collapsed }),

  // 设置面包屑
  setBreadcrumbs: (breadcrumbs) => set({ breadcrumbs }),
}));

